package com.uduew.sjd.ui.web

import android.os.Bundle
import com.uduew.sjd.BR
import com.uduew.sjd.R
import com.uduew.sjd.ui.base.BaseActivity
import com.uduew.sjd.ui.base.StateHolder
import com.hjq.bar.OnTitleBarListener
import com.hjq.bar.TitleBar
import com.kunminx.architecture.ui.page.DataBindingConfig
import com.kunminx.architecture.ui.state.State

class WebViewActivity : BaseActivity() {
    private lateinit var mStates: States

    override fun initViewModel() {
        mStates = getActivityScopeViewModel(States::class.java)
    }


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        val url = intent.getStringExtra("URL")
        mStates.url.set(url.toString())
        val title = intent.getStringExtra("TITLE")
        mStates.title.set(title.toString())
    }

    override fun getDataBindingConfig(): DataBindingConfig? {
        return DataBindingConfig(R.layout.activity_web, BR.vm, mStates).addBindingParam(
            BR.click,
            ClickProxy()
        ).addBindingParam(BR.titleBarListener, TitleBarListener())
    }

    inner class TitleBarListener : OnTitleBarListener {
        override fun onLeftClick(titleBar: TitleBar?) {
            super.onLeftClick(titleBar)
            finish()
        }

        override fun onRightClick(titleBar: TitleBar?) {
            super.onRightClick(titleBar)
        }
    }

    open inner class ClickProxy {
        fun agreement() {
        }

        fun disagree() {
        }

    }


    open class States : StateHolder() {
        val url: State<String> = State("")
        val title: State<String> = State("")
    }

}